package com.ljh.account.config;
import com.ljh.account.Interceptor.AdminInterceptor;
import com.ljh.account.Interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;
    @Autowired
    private AdminInterceptor adminInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 所有以 /api/protected 开头的接口都必须登录
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/api/protected/**","/api/admin/**");
        // 所有以 /api/admin 开头的接口都必须为管理员
        registry.addInterceptor(adminInterceptor)
                .addPathPatterns("/api/admin/**");
    }
}